package com.zzyl.nursing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.mapper.FamilyMemberElderMapper;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.vo.member.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 客户老人家属关联Service业务层处理
 * 
 * @author alexis
 * @date 2025-06-07
 */
@Service
public class FamilyMemberElderServiceImpl extends ServiceImpl<FamilyMemberElderMapper, FamilyMemberElder> implements IFamilyMemberElderService
{
    @Autowired
    private FamilyMemberElderMapper familyMemberElderMapper;

    /**
     * 查询客户老人家属关联
     * 
     * @param id 客户老人家属关联主键
     * @return 客户老人家属关联
     */
    @Override
    public FamilyMemberElder selectFamilyMemberElderById(Long id)
    {
        return familyMemberElderMapper.selectById(id);
    }

    /**
     * 查询客户老人家属关联列表
     * 
     * @param familyMemberElder 客户老人家属关联
     * @return 客户老人家属关联
     */
    @Override
    public List<FamilyMemberElder> selectFamilyMemberElderList(FamilyMemberElder familyMemberElder)
    {
        return familyMemberElderMapper.selectFamilyMemberElderList(familyMemberElder);
    }

    /**
     * 新增客户老人家属关联
     * 
     * @param familyMemberElder 客户老人家属关联
     * @return 结果
     */
    @Override
    public int insertFamilyMemberElder(FamilyMemberElder familyMemberElder)
    {
        return familyMemberElderMapper.insert(familyMemberElder);
    }

    /**
     * 修改客户老人家属关联
     * 
     * @param familyMemberElder 客户老人家属关联
     * @return 结果
     */
    @Override
    public int updateFamilyMemberElder(FamilyMemberElder familyMemberElder)
    {
        return familyMemberElderMapper.updateById(familyMemberElder);
    }

    /**
     * 批量删除客户老人家属关联
     * 
     * @param ids 需要删除的客户老人家属关联主键
     * @return 结果
     */
    @Override
    public int deleteFamilyMemberElderByIds(Long[] ids)
    {
        return familyMemberElderMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除客户老人家属关联信息
     * 
     * @param id 客户老人家属关联主键
     * @return 结果
     */
    @Override
    public int deleteFamilyMemberElderById(Long id)
    {
        return familyMemberElderMapper.deleteById(id);
    }


    @Override
    public List<PageResult> queryPage(Integer pageNum, Integer pageSize) {
        Page<FamilyMemberElder> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<FamilyMemberElder> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FamilyMemberElder::getFamilyMemberId,UserThreadLocal.get());
        page=page(page,wrapper);
        List<FamilyMemberElder> records = page.getRecords();
        List<PageResult>pageResultList=familyMemberElderMapper.selectAll(records);
        return pageResultList;

    }
}
